package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author stone
 * @date 2022/09/02 15:24
 */
@RestController
public class RESTfulController {

    /*@RequestMapping("google19890102/article/details/126234638")
    public BaseRespVo articleDetails() {
        // 可以映射到这个Handler方法，但是它合理吗？
        return BaseRespVo.ok();
    }*/
    //@RequestMapping("*/article/details/*")
    //public BaseRespVo articleDetails(HttpServletRequest request) {
    //    StringBuffer requestURL = request.getRequestURL();
    //    return BaseRespVo.ok();
    //}

    @RequestMapping("{username}/article/details/{id}")
    public BaseRespVo articleDetails(@PathVariable("username") String username,
                                     @PathVariable("id") Integer id) {
        return BaseRespVo.ok();
    }

    //localhost:8080/param/login?username=songge&password=niupi
    // 脱裤子放屁 → 可以但没必要 → 限定你必须携带对应的请求参数
    @RequestMapping("param/login")
    //public BaseRespVo login(String username, String password) {
    public BaseRespVo login(@RequestParam("username") String param1,
                            @RequestParam("password") String param2) {
        return BaseRespVo.ok();
    }

    @RequestMapping("header")
    public BaseRespVo header(@RequestHeader("Host") String host,
                             @RequestHeader("Accept") String[] accept) {
        return BaseRespVo.ok();
    }

    @RequestMapping("cookies2")
    public BaseRespVo cookies2(@CookieValue("songge") String songge) {
        return BaseRespVo.ok();
    }

    @RequestMapping("session/put/{username}")
    public BaseRespVo sessionPut(@PathVariable("username") String username, HttpSession session) {
        session.setAttribute("username", username);
        return BaseRespVo.ok();
    }

    @RequestMapping("session/get")
    public BaseRespVo sessionGet(@SessionAttribute("username") Object username) {
        return BaseRespVo.ok();
    }
}
